package com.ciwong.epaper.modules.me.adapter;

import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.ciwong.epaper.R;
import com.ciwong.epaper.modules.me.bean.Price;
import com.ciwong.epaper.modules.me.bean.Service;
import java.util.List;

/**
 * Created by yyf on 2017/8/30.
 */

public class BuyServicePriceAdapter extends BaseCommonAdapter {
    private Service service;
    private Price curPrice;

    public BuyServicePriceAdapter(List<Price> dataList, Service service) {
        super(dataList);
        this.service = service;
    }

    @Override
    public int getItemResId(int position) {
        return R.layout.item_service_price;
    }

    @Override
    public Object createViewHolder(View convertView, int position) {
        ViewHolder viewHolder = new ViewHolder();
        viewHolder.iv_checked = (ImageView) convertView.findViewById(R.id.iv_checked);
        viewHolder.tv_price = (TextView) convertView.findViewById(R.id.tv_price);
        viewHolder.tv_discoint_sale = (TextView) convertView.findViewById(R.id.tv_discoint_sale);
        viewHolder.ll_price_item = (LinearLayout) convertView.findViewById(R.id.ll_price_item);
        return viewHolder;
    }

    @Override
    public void showData(Object bean, Object holder, int position) {
        Price price = (Price) bean;
        ViewHolder viewHolder = (ViewHolder) holder;
        if (price.checked) {
            viewHolder.iv_checked.setBackgroundResource(R.drawable.check_box_check_true1);
        } else {
            viewHolder.iv_checked.setBackgroundResource(R.drawable.check_box_check_false1);
        }
        java.text.DecimalFormat   decimalFormat   =new   java.text.DecimalFormat("#0.00");
        if (service.getSign() == 1 || service.getSign() == 3) {//买断和免费模式
//            String str_price = price.getPrice() + "元";
//            viewHolder.tv_price.setText(str_price);
            String df_price=decimalFormat.format(price.getPrice())+"元";
            viewHolder.tv_price.setText(df_price);
        } else {//按月付费模式
            String str_price = price.getUnit() + "个月/" + decimalFormat.format(price.getPrice())+"元";
            viewHolder.tv_price.setText(str_price);
        }
    }

    private class ViewHolder {
        public ImageView iv_checked;
        public TextView tv_price;
        public LinearLayout ll_price_item;
        public TextView tv_discoint_sale; //折扣
    }
    public List<Price> getData(){
        return dataList;
    }
}
